1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : ressourcen/classes/class.filemanager.inc.php
5 : - Modulgruppe: File Manager
6 : - Beschreibung: Neuer, revolutionaerer File Manager
7 : - Version: 0.4, 25/09/05
8 : - Autor(en): Thorsten Buss <admin@drstone.de>
9 : Michael Plefka <freAk0r@gmx.net>
10 : +---------------------------------------------------------------------------+
11 : This program is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU General Public License
13 : as published by the Free Software Foundation; either version 2
14 : of the License, or any later version.
15 : +---------------------------------------------------------------------------+
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 : You should have received a copy of the GNU General Public License
21 : along with this program; if not, write to the Free Software
22 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 : +--------------------------------------------------------------------------*/
24 :
25 1 : if ( !defined("PATH_TO_ROOT") ) {
26 0 : define( "PATH_TO_ROOT", "../../" );
27 0 : }
28 :
29 : /**
30 : * File Manager
31 : * @package eStudy.Ressourcen
32 : * @version 0.4, 12/08/06
33 : * @author Thorsten Buss <admin@drstone.de>
34 : * @author Michael Plefka <freAk0r@gmx.net>
35 : * @author Corinna Kropf <corinna_kropf@web.de>
36 : */
37 : /** Einbinden der Formatierungs Klasse */
38 1 : require_once ("class.format.inc.php");
39 1 : require_once ("class.roleartefacts.inc.php");
40 1 : require_once ("class.teamartefacts.inc.php");
41 :
42 : /** Die Spider-Klasse der Suchmaschine einbinden */
43 1 : require_once ("class.spider.inc.php");
44 :
45 1 : require_once ("class.folder.inc.php");
46 1 : require_once ("class.file.inc.php");
47 :
48 1 : require_once ("class.zipprovider.inc.php");
49 1 : require_once ("class.archiverexception.inc.php");
50 :
51 : /**
52 : * File Manager
53 : * @package eStudy.Ressourcen
54 : * @version 0.3, 25/09/05
55 : * @author Thorsten Buss <admin@drstone.de>
56 : * @author Michael Plefka <freAk0r@gmx.net>
57 : */
58 1 : class Filemanager {
59 : private $mimeTypes = array();
60 : private $imgFolder;
61 : private $activeFolder;
62 : private $action;
63 : private $actionID;
64 : private $visibleFiles;
65 : /**
66 : * Konstruktor
67 : *
68 : * @access public
69 : */
70 : public function Filemanager() {
71 0 : global $db, $resDB;
72 0 : $this->imgFolder = PATH_TO_ROOT.'ressourcen/icons/';
73 : // Liste mit Mimetypen f�llen
74 0 : $this->mimeTypes = array('ez' => 'application/andrew-inset', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 'bin' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'class' => 'application/octet-stream', 'so' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'bcpio' => 'application/x-bcpio', 'vcd' => 'application/x-cdlink', 'pgn' => 'application/x-chess-pgn', 'cpio' => 'application/x-cpio', 'csh' => 'application/x-csh', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'spl' => 'application/x-futuresplash', 'gtar' => 'application/x-gtar', 'hdf' => 'application/x-hdf', 'js' => 'application/x-javascript', 'skp' => 'application/x-koan', 'skd' => 'application/x-koan', 'skt' => 'application/x-koan', 'skm' => 'application/x-koan', 'latex' => 'application/x-latex', 'nc' => 'application/x-netcdf', 'cdf' => 'application/x-netcdf', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 'texinfo' => 'application/x-texinfo', 'texi' => 'application/x-texinfo', 't' => 'application/x-troff', 'tr' => 'application/x-troff', 'roff' => 'application/x-troff', 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'ms' => 'application/x-troff-ms', 'ustar' => 'application/x-ustar', 'src' => 'application/x-wais-source', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => 'application/zip', 'au' => 'audio/basic', 'snd' => 'audio/basic', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'kar' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'm3u' => 'audio/x-mpegurl', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 'wav' => 'audio/x-wav', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-xyz', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'ief' => 'image/ief', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'djvu' => 'image/vnd.djvu', 'djv' => 'image/vnd.djvu', 'wbmp' => 'image/vnd.wap.wbmp', 'ras' => 'image/x-cmu-raster', 'pnm' => 'image/x-portable-anymap', 'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'ppm' => 'image/x-portable-pixmap', 'rgb' => 'image/x-rgb', 'xbm' => 'image/x-xbitmap', 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-xwindowdump', 'igs' => 'model/iges', 'iges' => 'model/iges', 'msh' => 'model/mesh', 'mesh' => 'model/mesh', 'silo' => 'model/mesh', 'wrl' => 'model/vrml', 'vrml' => 'model/vrml', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'asc' => 'text/plain', 'txt' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'sgml' => 'text/sgml', 'sgm' => 'text/sgml', 'tsv' => 'text/tab-separated-values', 'wml' => 'text/vnd.wap.wml', 'wmls' => 'text/vnd.wap.wmlscript', 'etx' => 'text/x-setext', 'xsl' => 'text/xml', 'xml' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'mxu' => 'video/vnd.mpegurl', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'ice' => 'x-conference/x-cooltalk',);
75 0 : $this->activeFolder = isset($_GET['activeFolder']) ? $_GET['activeFolder'] : 0;
76 0 : $this->action = isset($_GET['action']) ? $_GET['action'] : '';
77 0 : $this->actionID = isset($_GET['actionID']) ? $_GET['actionID'] : 0;
78 0 : $this->visibleFiles = $db->get_col("SELECT fileID FROM filevisible WHERE userID='".$_SESSION["userid"]."'");
79 0 : $resDB = new RessourcenDB( $this );
80 0 : }
81 :
82 : public function getActiveFolder() {
83 0 : return $this->activeFolder;
84 : }
85 :
86 : public function getAction() {
87 0 : return $this->action;
88 : }
89 :
90 : public function getActionID() {
91 0 : return $this->actionID;
92 : }
93 :
94 : public function getImgFolder() {
95 0 : return $this->imgFolder;
96 : }
97 :
98 : /**
99 : * Erstellt den Verzeichnisbaum und gibt ihn aus
100 : *
101 : * @access public
102 : */
103 : function showTree() {
104 0 : global $db;
105 0 : $template = new Template( PATH_TO_ROOT . "/ressourcen/templates/foldertree.html" );
106 0 : $tree_entries = "";
107 :
108 : //Bestimmung der Anzeigeoptionen fuer spezielle User
109 : // INIT
110 0 : $course = $_SESSION['course'];
111 : // Setzt Standards fuer die Symbole
112 0 : $plus = 8;
113 0 : $minus = 6;
114 0 : $join = 3;
115 0 : $bottom = false;
116 : // MostDownloaded Files
117 0 : $last20 = new Folder(-2);
118 0 : $last20->setLink("Last 20");
119 0 : $last20->setName("Die 20 neuesten Dateien dieses Kurses.");
120 0 : $last20->setFolderType(13);
121 0 : $last20->setLayerType(5);
122 0 : $tree_entries .= $last20->drawFolder("", false);
123 :
124 0 : $last20 = new Folder(-1);
125 0 : $last20->setLink("Top 20");
126 0 : $last20->setName("Die 20 beliebtesten Dateien dieses Kurses.");
127 0 : $last20->setFolderType(12);
128 0 : $last20->setLayerType(5);
129 0 : $tree_entries .= $last20->drawFolder("", false);
130 :
131 0 : $mainFolder = new Folder();
132 0 : $mainFolder->setFileManager( $this );
133 0 : if ($Return = $mainFolder->printSubFolder()) {
134 0 : $tree_entries .= $Return;
135 0 : } else {
136 0 : $tree_entries .= "<span class='tableCell'>Noch keine Ordner angelegt.</span>";
137 : }
138 0 : eval ( $template->getTemplate() );
139 0 : }
140 :
141 : function showFiles( $statisticView = false ) {
142 0 : global $resDB;
143 0 : if ( $this->activeFolder > 0 ) {
144 0 : $folder = $resDB->getFolderByID( $this->activeFolder );
145 0 : if (!$folder || !$this->canSeeFile($this->activeFolder)) //Nicht berechtigte Usergruppen dürfen den Ordner und seinen Inhalt nicht sehen
146 : //oder downloaden, auch nicht durch explizite Angabe des Links
147 0 : {
148 0 : return "Keine solche Ressource verfügbar!";
149 : }
150 0 : } else {
151 0 : if ($this->activeFolder == -1) {
152 0 : $folder = new Folder(-1);
153 0 : $folder->setFileManager( $this );
154 0 : $folder->setLink("Top 20");
155 0 : }
156 0 : if ($this->activeFolder == -2) {
157 0 : $folder = new Folder(-2);
158 0 : $folder->setFileManager( $this );
159 0 : $folder->setLink("20 neuesten Ressourcen");
160 0 : }
161 : }
162 :
163 0 : $folder->showFiles( $statisticView );
164 0 : }
165 :
166 : /**
167 : * Führt eine Aktion aus, die vom User ausgewählt wurde.
168 : *
169 : * @param object [$file] details der aktuellen Datei, oder folderID
170 : * @param int [$COLS] Anzahl der Spalten der Filelist, wird fuer Colspan benoetigt
171 : * @param string $action Durchzuführende Aktion, fehlt diese Angabe, wird der GET-Parameter verwendet
172 : * @param int $actionID ID des Objekts, auf das die Aktion angewandt werden soll, fehlt diese Angabe, wird der GET-Parameter verwendet
173 : * @param int $activeFolder ID des aktuellen Verzeichnisses, fehlt diese Angabe, wird der GET-Parameter verwendet
174 : * @access private
175 : */
176 : function runAction($file, $COLS, $action = "", $actionID = "", $activeFolder = "") {
177 0 : global $db;
178 0 : if (empty($activeFolder)) $activeFolder = $_GET['activeFolder'];
179 0 : if (empty($action)) $action = isset($_GET['action']) ? $_GET['action'] : '';
180 0 : if (empty($actionID)) $actionID = isset($_GET['actionID']) ? $_GET['actionID'] : '';
181 0 : if (!$action || (is_object($file) && $file->fileID != $actionID) || (!is_object($file) && $file != $actionID)) return false;
182 : switch ($action) {
183 0 : case 'delete_trueFile':
184 0 : if ($_SESSION['userid'] == $file->userID || $_SESSION['usergroup'] == ADMIN || ($_SESSION["usergroup"] == DOZENT && $_SESSION["course"] > 0)) {
185 0 : if ($file->type == 'file') { // Wenn Datei dann loeschen
186 0 : $this->deleteFile($file->link);
187 : // Datei aus Suchmaschinen-Index löschen
188 0 : $spider = new Spider();
189 0 : $spider->start("remove-file", $file->fileID);
190 0 : }
191 0 : $db->query("DELETE FROM filelist WHERE fileID='$file->fileID'");
192 0 : $db->query("DELETE FROM filelog WHERE fileID='$file->fileID'");
193 0 : $db->query("DELETE FROM filevisible WHERE fileID='$file->fileID'");
194 0 : RoleArtefacts::deleteItem(RESSOURCE, (int)$file->fileID);
195 0 : TeamArtefacts::deleteItem(RESSOURCE, (int)$file->fileID);
196 0 : } else {
197 0 : return "Zugriff verweigert!";
198 : }
199 0 : break;
200 :
201 0 : case 'delete_trueFolder':
202 0 : if ($_SESSION['usergroup'] == ADMIN || ($_SESSION["usergroup"] == DOZENT && $_SESSION["course"] > 0)) {
203 0 : $this->deleteFolder($activeFolder);
204 0 : unset($_GET['activeFolder']);
205 0 : } else {
206 0 : return "Zugriff verweigert!";
207 : }
208 0 : break;
209 :
210 :
211 0 : case 'editFolder':
212 0 : break;
213 :
214 0 : case 'studentWriteFolder':
215 0 : if ($_SESSION['usergroup'] != 2) {
216 0 : $writeState = $db->get_var("SELECT student_write FROM filelist WHERE fileID='$actionID' ");
217 0 : $writeState = ($writeState == 1 ? 0 : 1);
218 0 : $db->query("UPDATE filelist SET student_write='$writeState' WHERE fileID='$actionID'");
219 0 : } else {
220 0 : echo "<tr><td class='res_file-extra' colspan='".$COLS."'>Zugriff verweigert!</td>";
221 : }
222 0 : break;
223 :
224 0 : case 'setVisibilityDocentsOnly':
225 0 : if (isset($_GET['mode'])) $this->setRessourceVisibility($actionID, 3, $_GET['mode']);
226 0 : else $this->setRessourceVisibility($actionID, 3, 1);
227 0 : header('Location: filemanager.php?activeFolder='.$activeFolder);
228 0 : break;
229 :
230 0 : case 'setVisibilityNoStudents':
231 0 : if (isset($_GET['mode'])) $this->setRessourceVisibility($actionID, 2, $_GET['mode']);
232 0 : else $this->setRessourceVisibility($actionID, 2, 1);
233 0 : header('Location: filemanager.php?activeFolder='.$activeFolder);
234 0 : break;
235 :
236 0 : case 'setVisibilityAll':
237 0 : if (isset($_GET['mode'])) $this->setRessourceVisibility($actionID, 1, $_GET['mode']);
238 0 : else $this->setRessourceVisibility($actionID, 1, 1);
239 0 : header('Location: filemanager.php?activeFolder='.$activeFolder);
240 0 : break;
241 : }
242 0 : }
243 :
244 : /**
245 : * Löscht einen Ordner mit allem Inhalt und Unterordnern
246 : *
247 : * @param int [$folderID] ID des zu loeschenden Ordners
248 : * @return boolean Erfolgswert
249 : * @access private
250 : */
251 : function deleteFolder($folderID) {
252 0 : global $db, $EZSQL_ERROR;
253 0 : $folders = $db->get_results("SELECT type, fileID, link FROM filelist WHERE parent_object='$folderID'");
254 0 : if ($folders) {
255 0 : foreach($folders as $folder) {
256 0 : if ($folder->type == "file") {
257 0 : $this->deleteFile($folder->link);
258 : // Datei aus Suchmaschinen-Index löschen
259 0 : $spider = new Spider();
260 0 : $spider->start("remove-file", $folder->fileID);
261 0 : }
262 0 : $this->deleteFolder($folder->fileID);
263 0 : }
264 0 : }
265 0 : $errorCount = count($EZSQL_ERROR);
266 0 : $db->query("DELETE FROM filelist WHERE fileID='$folderID'");
267 0 : $db->query("DELETE FROM filelog WHERE fileID='$folderID'");
268 0 : $db->query("DELETE FROM filetreelayout WHERE folderID='$folderID'");
269 0 : $db->query("DELETE FROM filevisible WHERE fileID='$folderID'");
270 0 : RoleArtefacts::deleteItem(RESSOURCE, (int)$folderID);
271 0 : TeamArtefacts::deleteItem(RESSOURCE, (int)$folderID);
272 0 : if (count($EZSQL_ERROR) > $errorCount) return false;
273 0 : return true;
274 : }
275 : /**
276 : * Löscht eine Datei physikalisch
277 : *
278 : * @param string [$file] Dateiname der Datei
279 : * @return boolean Erfolgswert
280 : * @access private
281 : */
282 : function deleteFile($file) {
283 0 : global $settings;
284 0 : $basedir = PATH_TO_ROOT.$settings["upload_path"].'filemanager/courseID/'.$_SESSION['course'];
285 0 : if (!file_exists($basedir."/".$file)) return false;
286 0 : if (!unlink($basedir."/".$file)) return false;
287 0 : return true;
288 : }
289 : /*
290 : * Ändert die Sichtbarkeit der Ressource (Order, Datei oder Link)
291 : *
292 : * @param string [$ressourceID] Name der Ressource
293 : * @param int [$visibilityToSet] neuer Wert für die Sichbarkeit der Ressource
294 : * @param int [$contentRecursive] 1 wenn nur die Ressource geändert werden soll (Ordner werden dann wie Dateien und Links behandelt)
295 : * 2 wenn bei einem Ordner nur der Inhalt (rekursiv) geändert werden soll,
296 : * 3 wenn Ordner und Inhalt (rekursiv) geändert werden sollen,
297 : * @return boolean Erfolgswert
298 : * @access private
299 : */
300 : private function setRessourceVisibility($ressourceID, $visibilityToSet, $contentRecursive) {
301 0 : global $db, $EZSQL_ERROR;
302 : // Momentane Sichtbarkeit der Ressource aus der DB auslesen
303 0 : $visible = $db->get_var("SELECT visible_type FROM filelist WHERE fileID='$ressourceID'");
304 : // Ressource hat schon die gewünschte Sichtbarkeit
305 0 : if ($visible == $visibilityToSet && $contentRecursive == 1) return true;
306 : // Wenn die Ressource ein Ordner ist und dessen Sichtbarkeit eingeschränkt werden soll:
307 : // Sichtbarkeit untergeordneter Ordner, Dateien und Links ändern
308 0 : if ($contentRecursive > 1) {
309 0 : $ressources = $db->get_results("SELECT type, fileID, link , visible_type FROM filelist WHERE parent_object='$ressourceID'");
310 0 : if ($ressources != null) {
311 : // Sichtbarkeit der untergeordneten Ressource nur ändern,
312 : // wenn sie eingeschränkt werden soll; Alle Unterordner durchgehen
313 0 : foreach($ressources as $ressource) {
314 : //für alle Dateien und Links in dem Ordner
315 0 : if ($ressource->type == "file") {
316 0 : $this->setRessourceVisibility($ressource->link, $visibilityToSet, $contentRecursive);
317 0 : }
318 : //für den Ordner selbst, alle Unterordner und deren Inhalt
319 0 : if ($contentRecursive == 2) $this->setRessourceVisibility($ressource->fileID, $visibilityToSet, 4);
320 0 : else $this->setRessourceVisibility($ressource->fileID, $visibilityToSet, $contentRecursive);
321 0 : }
322 0 : }
323 0 : }
324 : //Ressource mit ID $ressourceID in der DB ändern
325 0 : if ($contentRecursive != 2) {
326 : // Sichtbarkeitswerte für die Ressource auf der Datenbank updaten
327 0 : $errorCount = count($EZSQL_ERROR);
328 0 : $db->query("UPDATE filelist SET visible_type ='$visibilityToSet' WHERE fileID='$ressourceID'");
329 0 : $visible = $db->get_var("SELECT visible_type FROM filelist WHERE fileID='$ressourceID'");
330 0 : if (count($EZSQL_ERROR) > $errorCount) return false;
331 0 : if ($contentRecursive > 2) {
332 0 : $db->query("DELETE FROM filevisible WHERE fileID='".$ressourceID."'");
333 0 : }
334 0 : }
335 0 : return true;
336 : }
337 : /**
338 : * Erstellt einen Link mit GET Variablen
339 : *
340 : * @param bool [$oldOnes] Gibt an ob bisher existierende GET Variablen mit in den Link eingebaut werden.
341 : * @param array [$vars] Ein Array (Aufbau wie $_GET) mit den Variabeln und WErten die in den Link eingebaut werden
342 : * @param string [$link] Falls nicht PHP_SELF das Ziel ist muss hier der Dateiname angegeben werden.
343 : * @return string Zusammengesetzter Link
344 : * @access private
345 : */
346 : function createLink($oldOnes = true, $vars = '', $link = '') {
347 0 : if ($link == "") $link = PATH_TO_ROOT.SCRIPT_NAME;
348 0 : if (!is_array($vars)) $vars = $_GET;
349 0 : elseif (count($_GET) > 0 && $oldOnes) $vars = array_merge($_GET, $vars);
350 0 : foreach($vars as $getVarName => $getVarValue) {
351 0 : if (trim($getVarValue) != "" && isset($getVarValue)) $getVars[] = urlencode($getVarName) ."=".urlencode($getVarValue);
352 0 : }
353 0 : return $link."?".implode($getVars, "&");
354 : }
355 : /**
356 : * Schickt eine auf dem Server liegende Datei an den Browser
357 : *
358 : * @param int [$fileID] Die ID des zu sendenden Files
359 : * @return string Zusammengesetzter Link
360 : * @access private
361 : */
362 : function downloadFile($fileID) {
363 0 : global $settings, $db;
364 : // Dateiname generieren
365 0 : $file = $db->get_row("SELECT name, link, size, extension, orig_filename, courseID FROM filelist WHERE fileID='".$fileID."'");
366 0 : if (!$this->canSeeFile($fileID)) {
367 0 : return "Sie haben keine Berechtigung diese Datei herunterzuladen!";
368 : }
369 : // Verzeichnis dass die hochgeladenen Dateien enthält
370 0 : $basedir = PATH_TO_ROOT.$settings["upload_path"].'filemanager/courseID/'.$file->courseID;
371 : //die datei wie sie auf dem server liegt (der dateiname ist verschlüsselt)
372 0 : $filename = sprintf("%s/%s", $basedir, $file->link);
373 0 : if (!file_exists($filename)) return "Datei nicht vorhanden, bitte wenden Sie sich an den Administrator!";
374 : //den mimetypen bestimmen
375 0 : if (isset($this->mimeTypes[$file->extension])) {
376 0 : $mimetype = $this->mimeTypes[$file->extension];
377 0 : } else {
378 0 : $mimetype = "application/octet-stream";
379 : }
380 : // Zugriff wird geloggt
381 0 : $time = time();
382 0 : $db->query("INSERT INTO filelog (userID, fileID, date) VALUES ('".$_SESSION['userid']."','$fileID','$time')");
383 0 : $db->query("UPDATE filelist SET counter=counter+1 WHERE fileID='$fileID'");
384 : // Output-Buffering abschalten
385 0 : ob_end_clean();
386 : // HTTP Header Informationen senden, die ersten beiden sind wichtig für den IE
387 0 : header("Pragma: private");
388 0 : header("Cache-control: private, must-revalidate");
389 0 : header("Content-Type: $mimetype");
390 0 : header("Content-Disposition: attachment; filename=\"".$file->orig_filename."\"");
391 0 : header("Content-Transfer-Encoding: binary");
392 0 : header("Content-Length: ".$file->size);
393 : //die datei senden
394 0 : readfile($filename);
395 0 : return "";
396 : }
397 : /**
398 : * Öffnet einen Link in einem neuen Fenster (Gegenstück zu downloadFile für
399 : * Links)
400 : *
401 : * @param int [$fileID] ID des zu öffnenden Links
402 : * @access private
403 : */
404 : function openLink($fileID) {
405 0 : global $db;
406 0 : if (!$this->canSeeFile($fileID)) {
407 0 : return "Sie haben keine Berechtigung diesen Link zu öffnen!";
408 : }
409 : // Ziel Url ermitteln
410 0 : $link = $db->get_var("SELECT link FROM filelist WHERE fileID='".$fileID."'");
411 : // Zugriff wird geloggt
412 0 : $time = time();
413 0 : $db->query("INSERT INTO filelog (userID, fileID, date) VALUES ('".$_SESSION['userid']."','$fileID','$time')");
414 0 : $db->query("UPDATE filelist SET counter=counter+1 WHERE fileID='$fileID'");
415 0 : if (Utilities::validateURL($link)) header("Location: ".$link);
416 0 : exit();
417 : }
418 : /**
419 : * Ersetzt bestimmte Zeichen mit einem _
420 : *
421 : * @param string [$string] String in dem Zeichen ersetzt werden sollen
422 : * @param string [$special] Ein String mit den SonderZeichen, die ersetzt
423 : * werden sollen
424 : * @return string String mit ersetzten Zeichen
425 : * @access private
426 : */
427 : function replaceSpecialChars($string, $special) {
428 0 : $strlen = strlen($special);
429 0 : for ($i = 0 ; $i <= $strlen ; $i++) {
430 0 : $char = substr($special, $i, 1);
431 0 : $string = str_replace($char, "_", $string);
432 0 : $string = str_replace("__", "_", $string);
433 0 : }
434 0 : $string = str_replace("__", "_", $string);
435 0 : return $string;
436 : }
437 : /**
438 : * Ermittelt Sichtbarkeits-/Downloadrechte von Userid auf fileId
439 : *
440 : * @param int [$fileID] Die ID des files (folder/link/file) zum Rechte ermitteln
441 : * @return bool Erfolgswert
442 : * @access private
443 : */
444 : function canSeeFile($fileID) {
445 : /* Sehen kann man wenn:
446 : - Man Admin/Dozent ist
447 : - Man Besitzer ist
448 : - Tutor und visibleMode=2
449 : - visibleMode=1
450 : - visibleMode aller übergeordneten Ordner != 1
451 : - Explizite User-Berechtigungen vorliegen */
452 0 : global $db;
453 : // Admin oder Dozent
454 0 : if ($_SESSION['usergroup'] == ADMIN || $_SESSION['usergroup'] == DOZENT) return true;
455 0 : $file = $db->get_row("SELECT courseID, userID, visible_type, parent_object FROM filelist WHERE fileID='$fileID'");
456 : // Es gibt keine solche Ressource
457 0 : if (!isset($file)) return false;
458 : // Wenn falscher Kurs gleich raus
459 0 : if (is_null($file) || $_SESSION['course'] != $file->courseID && $file->courseID != 0) return false;
460 : // Alle duerfen sehen
461 0 : if ($file->visible_type == 1) {
462 : // nur wenn die Datei nicht in einem für Studenten nicht freigegebenen (Über-)Ordner liegt
463 0 : $parentID = $file->parent_object;
464 0 : while ($parentID != 0) {
465 0 : $parentFolder = $db->get_row("SELECT visible_type, parent_object FROM filelist WHERE fileID='$parentID'");
466 0 : if ($parentFolder->visible_type > 1) return false;
467 0 : $parentID = $parentFolder->parent_object;
468 0 : }
469 0 : return true;
470 : }
471 : // Tutor
472 0 : if (isset($_SESSION['assistent']) && $file->visible_type == 2) {
473 : // nur wenn die Datei nicht in einem nur für Dozenten freigegebenen (Über-)Ordner liegt
474 0 : $parentID = $file->parent_object;
475 0 : while ($parentID != 0) {
476 0 : $parentFolder = $db->get_row("SELECT visible_type, parent_object FROM filelist WHERE fileID='$parentID'");
477 0 : if ($parentFolder->visible_type == 3) return false;
478 0 : $parentID = $parentFolder->parent_object;
479 0 : }
480 0 : return true;
481 : }
482 : // Besitzer
483 0 : if ($_SESSION['userid'] == $file->userID) return true;
484 : // Einzelberechtigung (gilt nicht, falls ein übergeordneter Ordner eine geringere Sichtbarkeit hat!!)
485 0 : if ($db->get_var("SELECT count(*) FROM filevisible WHERE fileID='$fileID' AND userID='".$_SESSION['userid']."'") > 0) return true;
486 0 : return false;
487 : }
488 :
489 : /**
490 : * Deliver a archive of the given folder.
491 : *
492 : * Depending on the configuration,
493 : * its possible that a recursive download archive is generated.
494 : *
495 : * @param Integer $folderID
496 : * @param Boolean $recursion (Default = False)
497 : * @return String
498 : */
499 : public function getArchivedFolder($folderID, $recursion = FALSE) {
500 0 : global $resDB;
501 0 : global $settings;
502 :
503 0 : if ($folderID > 0) {
504 0 : $folder = $resDB->getFolderByID($folderID);
505 :
506 0 : if (!$folder instanceof Folder) {
507 0 : return "Ordner mit der ID ".$folderID." wurde nicht gefunden.";
508 : }
509 0 : } elseif ($folderID == -2) {
510 0 : $folder = new Folder(-2);
511 0 : $folder->setLink("Last 20");
512 0 : $folder->setCourseID($_SESSION['course']);
513 0 : $folder->setDescription("Die 20 neuesten Dateien dieses Kurses.");
514 0 : } elseif ($folderID == -1) {
515 0 : $folder = new Folder(-1);
516 0 : $folder->setLink("Top 20");
517 0 : $folder->setCourseID($_SESSION['course']);
518 0 : $folder->setDescription("Die 20 beliebtesten Dateien dieses Kurses.");
519 0 : } else {
520 0 : return "Ordner mit der ID ".$folderID." wurde nicht gefunden.";
521 : }
522 :
523 : try {
524 0 : if (ZipProvider::checkArchiveSize($folder, $recursion) <=
525 0 : $settings['filemanager_archive_max_filesize']*1024*1024) {
526 :
527 0 : $zipProvider = new ZipProvider($folder, $recursion);
528 0 : $zipProvider->createArchive();
529 0 : $zipProvider->sendArchive();
530 0 : }
531 0 : } catch (ArchiverException $e) {
532 : return $e->getMessage();
533 : }
534 :
535 0 : return "";
536 : }
537 : }
|